

/***************************************************
 *                                                   												  *
 *            Login and new account javaScript functionality		      *
 * 																								  *	
 ***************************************************/

function validate()
{
		var username=document.newAccountForm.username.value;
		var password=document.newAccountForm.password.value;
		var repeatPassword=document.newAccountForm.repeatPassword.value;
		var nickname=document.newAccountForm.nickname.value;
		
		if(username=="")
		{
	    	 alert("Enter Username !");
		     return false;
		}
		if(password=="")
		{
		     alert("Enter Password !");
		     return false;
		}
		
		if(repeatPassword=="")
		{
		     alert("Enter Repeated Password !");
		     return false;
		}
		
		if(nickname=="")
		{
		     alert("Enter Nickname !");
		     return false;
		}
		
		if(!(password == repeatPassword))
		{
			 alert("Password and repeated password not equal !");
		     return false;
		}
		
		if(password.length < 5)
		{
			alert("You must enter at least 5 characters password !");
			return false;
		}
		
		var digitMatches = password.match(/\d+/g);
		if (digitMatches == null) 
		{
			 alert("Password must containt at least one digit !");
		     return false;
		}
		
		
		var letterMatches = password.match(/[a-zA-Z]/);
		
		if(letterMatches == null)
		{
			 alert("Password must containt at least one letter !");
		     return false;		
		}
			
		return true;
}

function validateUsername()
{
	var username = document.getElementById("username").value;
	
	if(username == "")
    {
		document.getElementById("errUsername").innerHTML = "Provide User";
		document.getElementById("errUsername").style.color = "red";
	}
	else
	{
		document.getElementById("errUsername").innerHTML = "OK";
		document.getElementById("errUsername").style.color = "green";
	}
	
}

function validatePassword()
{
	var password = document.getElementById("password").value;
	
	if(password == "")
    {
		document.getElementById("errPassword").innerHTML = "Provide Password";
		document.getElementById("errPassword").style.color = "red";
	}
	else
	{
		document.getElementById("errPassword").innerHTML = "OK";
		document.getElementById("errPassword").style.color = "green";
	}
}

function validateRepeatPassword()
{
	var repeatPassword = document.getElementById("repeatPassword").value;
	
	if(repeatPassword == "")
    {
		document.getElementById("errRepeatPassword").innerHTML = "Repeat Password";
		document.getElementById("errRepeatPassword").style.color = "red";
	}
	else
	{
		document.getElementById("errRepeatPassword").innerHTML = "OK";
		document.getElementById("errRepeatPassword").style.color = "green";
	}
}

function validateNickname()
{
var nickname = document.getElementById("nickname").value;
	
	if(nickname == "")
    {
		document.getElementById("errNickname").innerHTML = "Provide Nickname";
		document.getElementById("errNickname").style.color = "red";
	}
	else
	{
		document.getElementById("errNickname").innerHTML = "OK";
		document.getElementById("errNickname").style.color = "green";
	}
}

/***************************************************
 *                                                   												  *
 *                 Checkers Game javaScript functionality   				  *
 * 																								  *	
 ***************************************************/
var numOfSquares = 64;
var whiteSquare = "whiteSquare.jpg";
var blackSquare = "blackSquare.jpg";
var whiteChecker = "whiteChecker.jpg";
var blackChecker = "blackChecker.jpg";
//var whiteQueen = "photo.jpg";
//var blackQueen = "photo.jpg";
whiteSquare.width = 60;
whiteSquare.height = 60;
blackSquare.width = 60;
blackSquare.height = 60;
whiteChecker.width = 60;
whiteChecker.height = 60;
blackChecker.width = 60;
blackChecker.height = 60;

var checkers = new createArray(numOfSquares);
var checkerBoard = new createArray(numOfSquares);



function createArray(n)
{
	this.length = n;
	
	for(var i = 1; i <= n; i++)
	{
		this[i] = 0;
	}
	
	return this;
}

function displayBoard()
{
	giveCheckerNames(checkers, "checker", numOfSquares);
	
	fillBoard(checkerBoard, 
			
					whiteSquare, blackChecker , whiteSquare, blackChecker, whiteSquare, blackChecker, whiteSquare, blackChecker,			        
					blackChecker, whiteSquare , blackChecker, whiteSquare, blackChecker, whiteSquare, blackChecker, whiteSquare,					
					whiteSquare, blackChecker , whiteSquare, blackChecker, whiteSquare, blackChecker, whiteSquare, blackChecker,
					
					blackSquare, whiteSquare , blackSquare, whiteSquare, blackSquare, whiteSquare, blackSquare, whiteSquare,
					whiteSquare, blackSquare , whiteSquare, blackSquare, whiteSquare, blackSquare, whiteSquare, blackSquare,
					
					whiteChecker, whiteSquare , whiteChecker, whiteSquare, whiteChecker, whiteSquare, whiteChecker, whiteSquare,
					whiteSquare, whiteChecker , whiteSquare, whiteChecker, whiteSquare, whiteChecker, whiteSquare, whiteChecker,
					whiteChecker, whiteSquare , whiteChecker, whiteSquare, whiteChecker, whiteSquare, whiteChecker, whiteSquare
	
	);
	
	var game = this.document;
	
	for (var n = 1; n <= numOfSquares; n++) 
	{
	   // checkerboard.write('<a href="javascript:this.chooseMove(this.document.' + checkers[n] + ')">');
		game.write('<img src="' + checkerBoard[n] + '" name="' + checkers[n] + '" border="0">');
		game.write('</a>');

	    if ((n % 8) == 0) { game.write('<br>'); }
	  }
}

function giveCheckerNames(checkersArr, String, n)
{
	for(var i = 1; i <= n; i++)
	{
		checkersArr[i] = String + i;
	}
}

function fillBoard(boardArr)
{
	for(var i = 1; i < fillBoard.arguments.length; i++ )
	{
		boardArr[i] = fillBoard.arguments[i];
	}
}

